﻿
Public Module extensions
    <Extension()> Public Function [as](Of T)(ByVal i As Object) As T
        If i Is Nothing Then
            Return Nothing
        Else
            Try
                Return DirectCast(i, T)
            Catch
            End Try
            Try
                Return CType(i, T)
            Catch
            End Try

            assert(False, "failed to convert ", i.GetType().FullName(), " to ", GetType(T).FullName())
        End If
    End Function

    <Extension()> Public Function istype(Of T)(ByVal i As Object) As Boolean
        Return TypeOf i Is T
    End Function
End Module
